#include <iostream>
#include <sys/mman.h>
#include <unistd.h>

#define SIZE 4096

void *Mymalloc(size_t size)
{
    void *addr = mmap(nullptr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    if (addr == (void *)-1)
    {
        return nullptr;
    }
    return addr;
}

void Myfree(void *ptr, size_t size)
{
    munmap(ptr, size);
}

int main()
{
    char *addr = (char *)Mymalloc(SIZE);
    if (addr == nullptr)
    {
        std::cout << "Mymalloc failed!" << std::endl;
        return 1;
    }
    for (size_t i = 0; i < 26; i++)
    {
        addr[i] = 'a' + i;
    }

    // for (size_t i = 0; i < 26; i++)
    // {
    //     std::cout << addr[i] << std::endl;
    // }

    sleep(50);

    Myfree(addr, SIZE);
    return 0;
}